//
//  JLHeadline.m
//  LIangeNews
//
//  Created by sun on 16/1/17.
//  Copyright © 2016年 sun. All rights reserved.
//

#import "JLHeadline.h"
#import "JLHttpManager.h"
@implementation JLHeadline
-(instancetype)initWithDict:(NSDictionary *)dict{
    if (self = [super init]) {
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}
+(instancetype)headlineWithDict:(NSDictionary *)dict{
    return [[self alloc]initWithDict:dict];
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{};
+(void)headlineWithUrlString:(NSString *)urlString finished:(JLFinishedBlock)finished{
    NSString * doumainUrl = [kNetEaseDomin stringByAppendingString:urlString];
    doumainUrl = [NSString stringWithFormat:@"%@/0-140.html",doumainUrl];
    [[JLHttpManager shareManager] requestWithJLMethod:GET urlString:doumainUrl parameters:nil finished:^(NSDictionary * responseObject, NSError *error) {
        if (responseObject) {

//            [responseObject writeToFile:@"/Users/liang/Desktop/123.plist" atomically:YES];
            NSMutableArray * arrayM =[ NSMutableArray arrayWithCapacity:20];
            NSArray * array = responseObject[urlString];
            for (NSDictionary * dict in array) {
                JLHeadline * headline = [JLHeadline headlineWithDict:dict];
                [arrayM addObject:headline];
            }
            if (finished) finished(arrayM.copy,nil);
        }else{
            if (finished) finished(nil,error);
        }
    }];
    
    
}
@end
